<%@ page import="java.util.Date" %>
<%@ page import="java.util.Calendar" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="pg" uri="http://jsptags.com/tags/navigation/pager" %>
<link href="<c:url value="/resources/userInfo.css"/>" rel="stylesheet">
<html>
<head>
    <title>学生管理系统</title>
    <style type="text/css">
        body{
            padding: 0;
            margin: 0;
        }
        body,table{
            font-size:14px;
        }
        table{
            table-layout:fixed;
            empty-cells:show;
            border-collapse: collapse;
            margin:0 auto;
        }
        td{
            height:40px;
            width: 140px;
            text-align: center;
        }
        h1,h2,h3{
            font-size:12px;
            margin:0;
            padding:0;
        }
        .table{
            border:1px solid #cad9ea;
            color:#666;
        }
        .table th {
            background-repeat:repeat-x;
            height:30px;
        }
        .table td,.table th{
            border:1px solid #cad9ea;
            padding:0 1em 0;
        }
        .table tr.alter{
            background-color:#f5fafe;
        }
    </style>
</head>
<body>
<%
    Calendar now = Calendar.getInstance();
    int hour = now.get(Calendar.HOUR_OF_DAY);
    session.setAttribute("hour",hour);
%>

<div class="userInfo">
    <a href="/${currentUser.getUsername()}">
    ${currentUser.getUsername()}
    </a>，
        <c:if test="${hour > 0 && hour < 9}">
            早上好
        </c:if>
        <c:if test="${hour >= 9 && hour < 12}">
            上午好
        </c:if>
        <c:if test="${hour >= 12 && hour < 13}">
            中午好
        </c:if>
        <c:if test="${hour >= 13 && hour < 18}">
            下午好
        </c:if>
        <c:if test="${hour >= 18}">
            晚上好
        </c:if>
</div>
<div class="nav" style="position:relative;width:100%; height: 20%; text-align: center;line-height: 60px;z-index: 0">
    <strong><font style="size:36px;">查询记录</font></strong>
    <form class="search" action="${pageContext.request.contextPath}/queryAll?pageNow=1" method="post">
        <label>
            输入名字搜索：<input type="text" name="username"/>
        </label>
        <input style="border: none;border-radius: 3px;width:50px;height:25px;background: rgb(220,221,223)" type="submit" value="搜索">
    </form>
    <%--<div class="addOne">--%>
        <%--<a href="/add">新增用户</a>--%>
    <%--</div>--%>
</div>
<div class="allUsers">
    <table class="table">
        <tr>
            <td>username</td>
            <td>password</td>
            <td>gender</td>
            <td>desc</td>
            <td>操作</td>
            <td>添加用户</td>
        </tr>
        <!--循环遍历所有得到的记录并输出-->
        <c:forEach varStatus="statu" items="${recordList}" var="record">
            <tr style="
            <c:if test="${statu.count % 2 == 0}">
                    background: #ddedfb;
                    </c:if>"
            >
                <td>${record.username}</td>
                <td>${record.password}</td>
                <td>${record.gender}</td>
                <td>${record.desc}</td>
                <td>
                    <a href="${record.username}">详情</a>
                    <a href="update/${record.username}">修改</a>
                    <a href="${record.username}/delete">删除</a>
                </td>
                <td><a href="/add">添加用户</a></td>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="6">
                <!-- 分页功能 start -->
                <div align="center">
                    <font size="2">
                        <c:if test="${page.totalCount == 0}">
                            共 1页
                        </c:if>

                        <c:if test="${page.totalCount != 0}">
                            共 ${page.totalPageCount}页
                        </c:if>
                    </font> <font size="2">第
                    ${page.pageNow} 页</font> <a href="${pageContext.request.contextPath}/queryAll?pageNow=1&username=${username}">首页</a>
                    <pg:pager items="${page.totalCount}" export="currentPageNumber=pageNumber" maxPageItems="${page.pageSize}">
                        <!--访问路径中后置数据.效果如xx.do?method=search-->
                        <pg:param name="method" value="search"/>
                        <pg:pages>
                            <c:choose>
                                <c:when test="${page.pageNow eq pageNumber }">
                                    <a href="${pageContext.request.contextPath}/queryAll?pageNow=${pageNumber}&username=${username}" style="text-decoration: none;color: #000;">${pageNumber }</a>
                                </c:when>
                                <c:otherwise>
                                    <a href="${pageContext.request.contextPath}/queryAll?pageNow=${pageNumber}&username=${username}">${pageNumber }</a>
                                </c:otherwise>
                            </c:choose>
                        </pg:pages>
                    </pg:pager>
                    <c:choose>
                        <c:when test="${page.pageNow - 1 > 0}">
                            <a href="${pageContext.request.contextPath}/queryAll?pageNow=${page.pageNow - 1}&username=${username}">
                                上一页
                            </a>
                        </c:when>
                        <c:when test="${page.pageNow - 1 <= 0}">
                            <a href="${pageContext.request.contextPath}/queryAll?pageNow=1&username=${username}">
                                上一页
                            </a>
                        </c:when>
                    </c:choose>
                    <c:choose>
                        <c:when test="${page.totalPageCount==0}">
                            <a href="${pageContext.request.contextPath}/queryAll?pageNow=${page.pageNow}&username=${username}">下一页</a>
                        </c:when>
                        <c:when test="${page.pageNow + 1 < page.totalPageCount}">
                            <a href="${pageContext.request.contextPath}/queryAll?pageNow=${page.pageNow + 1}&username=${username}">下一页</a>
                        </c:when>
                        <c:when test="${page.pageNow + 1 >= page.totalPageCount}">
                            <a href="${pageContext.request.contextPath}/queryAll?pageNow=${page.totalPageCount}&username=${username}">下一页</a>
                        </c:when>
                    </c:choose>
                    <c:choose>
                        <c:when test="${page.totalPageCount==0}">
                            <a href="${pageContext.request.contextPath}/queryAll?pageNow=${page.pageNow}&username=${username}">尾页</a>
                        </c:when>
                        <c:otherwise>
                            <a href="${pageContext.request.contextPath}/queryAll?pageNow=${page.totalPageCount}&username=${username}">尾页</a>
                        </c:otherwise>
                    </c:choose>
                </div>
                <!-- 分页功能 End -->
            </td>
        </tr>
    </table>

</div>
</body>
</html>